package pl.nazaweb.jboot.afk;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marek Kawczyński
 */
public class TimerThread extends Thread {

    private ICallback callback;
    private long interval;

    public TimerThread(ICallback callback, long interval) {
        this.callback = callback;
        this.interval = interval;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(getInterval());
                callback.execute();
            } catch (InterruptedException ex) {
                Logger.getLogger(TimerThread.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public long getInterval() {
        return interval;
    }

    public void setInterval(long interval) {
        this.interval = interval;
    }
}
